﻿using MediatR;
using S.RBAC.Api.Application.Command.RoleJurisdictionCommand;
using S.RBAC.Domain.Model;
using S.RBAC.Infrastructure.Interface;

namespace S.RBAC.Api.Application.CommandHandlers.RoleJurisdictionHandler
{
    public class RoleJurisdictionCreateCommandHandler : IRequestHandler<RoleJurisdictionCreateCommand, int>
    {
        protected readonly IRoleJurisdictionRepository _roleJurisdiction;

        public RoleJurisdictionCreateCommandHandler(IRoleJurisdictionRepository roleJurisdiction)
        {
            _roleJurisdiction = roleJurisdiction;
        }

        public async Task<int> Handle(RoleJurisdictionCreateCommand request, CancellationToken cancellationToken)
        {
            return await _roleJurisdiction.AddRoleJurisdiction(new RoleJurisdiction
            {
                JurisdictionId = request.JurisdictionId,
                OperationIds = request.OperationIds,
                RoleId = request.RoleId,
            });
        }
    }
}
